package cn.com.bluemoon.daps.model.dto;


import cn.com.bluemoon.daps.model.entity.DapDataModelSubordinateKey;
import cn.com.bluemoon.daps.model.entity.DapDataModelTable;
import cn.com.bluemoon.daps.model.entity.DapDataModelTableField;
import cn.com.bluemoon.daps.model.entity.DapDataModelTablePartition;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * 模型表
 *
 * @author Jarod.Kong
 * @date 2020/9/25 14:35
 */
@Data
@Builder
@ToString
@AllArgsConstructor
public class ModelTableDto {

    /**
     * 表schema
     */
    private String schemaName;

    /**
     * 表信息
     */
    private DapDataModelTable table;

    /**
     * 字段信息
     */
    private List<DapDataModelTableField> fields = Lists.newArrayList();

    private List<DapDataModelSubordinateKey> indexes = Lists.newArrayList();

    private List<DapDataModelTablePartition> partitions = Lists.newArrayList();

    public ModelTableDto(){}

    public ModelTableDto(DapDataModelTableDto modelTableDto) {
        DapDataModelTable dapDataModelTable = new DapDataModelTable();
        BeanUtils.copyProperties(modelTableDto, dapDataModelTable);
        dapDataModelTable.setId(modelTableDto.getTableId());
        dapDataModelTable.setPId(modelTableDto.getPId());
        this.table = dapDataModelTable;
        this.fields = modelTableDto.getFieldList();
    }
}
